//
// Created by 12992 on 24-10-23.
//

#ifndef MEDIA_TRANSCODER_PROCESS_H
#define MEDIA_TRANSCODER_PROCESS_H

#include "muxer.h"
#include <functional>
#include <future>
#include <mutex>
#include <memory>

namespace utils
{
    class video_meta;

    class process
    {
        using muxer_ptr = std::shared_ptr<interfaces::muxer>;
        using callback = std::function<void(std::shared_ptr<interfaces::muxer>&)>;

    public:
        enum class status
        {
            NONE,
            RUNNING,
            PAUSE,
            DONE,
            ERROR
        };

        process(video_meta& meta, callback func);

        void start_process();

        void continue_process();

        void pause_process();

        status get_status() const;

        std::string get_error() const;

        int get_current_frame() const;

        int get_total_frames() const;

    private:
        std::shared_ptr<interfaces::muxer> muxer;
        callback func;
        mutable std::mutex status_lock{};
        status current_status{status::NONE};
        const int total_frames{0};
        std::atomic<bool> is_continue{false};
        std::atomic<bool> is_running{false};
        std::future<void> future;
        mutable std::mutex err_msg_lock{};
        std::string error_message;
    };
} // utils

#endif //MEDIA_TRANSCODER_PROCESS_H
